package persistance.hibernate;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class InitSessionFactory {

	private static SessionFactory sessionFactory;
	private static ServiceRegistry serviceRegistry;

	public static SessionFactory getInstance() {
	    if(sessionFactory == null){
	    	Configuration configuration = new Configuration();
	    	configuration.configure("hibernate.cfg.xml");
	 	    serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
	 	    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
	    }
	    return sessionFactory;
	}
	
}
